package com.ding.tags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class OutTag extends BodyTagSupport{
	private static final long serialVersionUID = 6659211161405525751L;

	int size;
	
	public void setSize(int size) {
		this.size = size;
	}
	
	public int getSize() {
		return size;
	}

	@Override
	public void setPageContext(PageContext pageContext) {
		System.out.println("传入页面上下文");
		super.setPageContext(pageContext);
	}
	@Override
	public int doStartTag() throws JspException {
		
		System.out.println("处理开始标签,"+"父标签:"+getParent());
		return super.doStartTag();
	}

	@Override
	public void setBodyContent(BodyContent b) {
		System.out.println("传入标签体内容");
		super.setBodyContent(b);
	}

	@Override
	public int doAfterBody() throws JspException {
		System.out.println("经过标签体");
		if (size>7) {
			size=7;
		}else if (size<1) {
			size=1;
		}
		size=7-size+1;
		try {
			pageContext.getResponse().getWriter().write("<h"+size+">"
					+getBodyContent().getString()
					+"</h"+size+">"
					);
		} catch (IOException e) {
		}
		return super.doAfterBody();
	}
	
	@Override
	public int doEndTag() throws JspException {
		
		System.out.println("处理结束标签");
		return super.doEndTag();
	}
	@Override
	public void release() {
		System.out.println("回收资源");
		super.release();
	}
	

}
